/**
 * @author zyj
 * @date 2022年06月06日 14:54
 */
public class 线程的礼让yield {
    public static void main(String[] args) {
        new Thread(){
            @Override
            public void run() {
                long start = System.currentTimeMillis();
                int sum = 0;
                for (int i = 0; i < 1000000; i++) {
                    sum += i;
                    yield();
                }

                long end = System.currentTimeMillis();
                System.out.println(Thread.currentThread().getName() + "执行的时间：" + (end-start));
            }
        }.start();

        long start = System.currentTimeMillis();
        int sum = 0;
        for (int i = 0; i < 1000000; i++) {
            sum += i;
        }

        long end = System.currentTimeMillis();
        System.out.println(Thread.currentThread().getName() + "执行的时间：" + (end-start));

    }
}


